<template>
  <view class="quest">
    <view class="wrap">
      <view class="t">{{ topicText }}</view>
      <view class="problem">
        <view class="p">任务名称:{{ quest.title }}</view>
        <view class="select">
          <view v-for="(item, index) in quest.testOptions" :key="item.id">
            <view class="item" @click="choice(abc[index])">
              <view v-if="iList.indexOf(abc[index])  == -1" class="chooseFalse">
                <u-icon color="#fff" name="checkbox-mark" size="24"></u-icon>
              </view>
              <view v-else class="chooseBoole">
                <u-icon color="#fff" name="checkbox-mark" size="24"></u-icon>
              </view>
              <view class="text">{{ abc[index] }}、{{ item.text }}</view>
            </view>
          </view>
        </view>
      </view>

      <view v-if="isComplete == true" class="remarkBox">
        <view v-if="quest.trueSelect == quest.userSelect" class="remarkTitle">
          回答正确!
        </view>
        <view v-else class="remarkTitle colorRed">
          回答错误!正确答案: {{ quest.trueSelect }}
        </view>
        <view class="">
          解释: {{ quest.remark != null ? quest.remark : "" }}
        </view>
      </view>
    </view>


  </view>
</template>

<script>
export default {
  data() {
    return {
      abc: [
        'A', 'B', 'C', 'D', 'E', 'F', 'G'
      ],
      i: null,
      abcList: [],
      iList: [],
      topicText: '单选题',

      isComplete: false,
    }
  },
  props: {
    quest: {
      type: Object,
      default: {}
    },
    completeCount: {
      typeof: Number,
      default: 0
    },
    sum: {
      typeof: Number,
      default: 0
    }
  },
  computed: {
    newCompleteCount() {
      return this.completeCount + 1 > this.sum ? this.sum : this.completeCount + 1
    }
  },
  onReady() {
    this.isComplete = this.quest.isComplete
    if (this.quest.trueSelect.length > 1) {
      this.topicText = '多选题'
    } else {
      this.topicText = '单选题'
    }
    if (this.quest.userSelect) {
      if (this.quest.userSelect.length > 0) {

        this.iList = []
        for (let i = 0; i < this.quest.userSelect.length; i++) {
          this.iList.push(this.quest.userSelect[i])
        }
      }
    }

  },
  methods: {
    clear() {
      this.i = null
    },
    choice(abc) {
      console.log('输出', abc);
      if (this.isComplete == false) {
        this.abcList = []
        for (let i = 0; i < this.quest.trueSelect.length; i++) {
          this.abcList.push(this.quest.trueSelect[i])
        }
        console.log('看', this.abcList);
        if (this.abcList.length > 1) {
          console.log(this.iList.indexOf(abc));
          if (this.iList.indexOf(abc) == -1) {
            this.iList.push(abc)
          } else {
            this.iList.splice(this.iList.indexOf(abc), 1)
          }

        } else {
          this.iList = [abc]
        }

        console.log('结果', this.iList);
        // this.i = abc
        this.$emit('choice', this.iList)
      }

    },
    onSubmit() {
      uni.showModal({
        content: '提交成功',
        cancelText: "重新选择",
        confirmText: "继续提交",
        success: (res) => {
          if (res.confirm) {
            this.toUrl('/pages/challenge/quest2')
          }
        }
      })
    },
    toUrl(url) {
      if (!url) return
      uni.navigateTo({
        url
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.quest {
  font-family: PingFang SC, PingFang SC-Heavy;

  .wrap {
    width: 100%;
    padding: 40rpx 30rpx;
    box-sizing: border-box;

    .t {
      width: 156rpx;
      height: 72rpx;
      line-height: 72rpx;
      text-align: center;
      background: #4186f5;
      border-radius: 6px 6px 0px 0px;
      color: #fff;
    }
  }

  .problem {
    border-radius: 0 12rpx 12rpx 12rpx;
    box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(0, 0, 0, 0.10);
    padding: 30rpx 40rpx 1rpx 40rpx;

    .p {
      font-size: 36rpx;
      font-weight: 800;
      color: #212121;
      margin-bottom: 20rpx;
    }

    .select {
      .item {
        display: flex;
        margin: 10px 0;

        .chooseFalse {
          width: 44rpx;
          height: 44rpx;
          background: #ffffff;
          border: 1px solid #dddddd;
          border-radius: 50%;
        }

        .chooseBoole {
          width: 44rpx;
          height: 44rpx;
          background: #4186f5;
          border: 1px solid #4186f5;
          border-radius: 50%;
          text-align: center;
        }

        .text {
          margin-left: 10px;
          font-size: 32rpx;
          font-weight: 400;
        }
      }

    }
  }

  .remarkBox {
    margin-top: 40rpx;
    border-radius: 0 12rpx 12rpx 12rpx;
    box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(0, 0, 0, 0.10);
    padding: 20rpx 20rpx;

    .remarkTitle {
      font-size: 36rpx;
      font-weight: 600;
      color: #4186f5;
    }

    .colorRed {
      color: red
    }
  }
}
</style>
